package com.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;

@Entity(name = "Activities")
public class Activity implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private long id;

	private String name;

	private String description;

	private int progress = 0;

	private Date startDate;

	private Date finishDate;

	private Employee employeeCreator;

	private Set<Task> tasks;
	
	private boolean isVisible;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getProgress() {
		return progress;
	}

	public void setProgress(int progress) {
		this.progress = progress;
	}

	@ManyToOne(targetEntity = Employee.class, cascade = CascadeType.PERSIST)
	public Employee getEmployeeCreator() {
		return employeeCreator;
	}

	public void setEmployeeCreator(Employee employee) {
		this.employeeCreator = employee;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(Date finishDate) {
		this.finishDate = finishDate;
	}

	@OneToMany (fetch = FetchType.EAGER, cascade = {CascadeType.ALL,CascadeType.REMOVE})
	@JoinColumn(name = "activity_id")
	public Set<Task> getTasks() {
		return tasks;
	}

	public void setTasks(Set<Task> tasks) {
		this.tasks = tasks;
	}

	@Override
	public boolean equals(Object obj) {

		if ((obj instanceof Integer)) {
			Integer a = (Integer) obj;
			return this.id == a;
		}
		if ((obj instanceof Activity)) {
			Activity activity = (Activity) obj;
			return this.id == activity.getId();
		}
		return super.equals(obj);
	}

	public boolean isVisible() {
		return isVisible;
	}

	public void setVisible(boolean isVisible) {
		this.isVisible = isVisible;
	}

}
